package domain;

import java.io.Serializable;
import java.math.BigDecimal;

public class Cart implements Serializable {
    private final String SRC_PREFIX = "<a href=\"ProductForm?productId=";
    private String SRC_POSTFIX = "class=\"small_img\"/></a>";
    public String curType = "small";
    private String productid;
    private String userid;
    private String imageSrc;
    private String name;
    private int cartid;
    private int num;
    private BigDecimal unitprice;
    private BigDecimal price;
    private boolean srcFix = false;

    public String getProductid() {
        return productid;
    }

    public void setProductid(String productid) {
        this.productid = productid;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getImageSrc() {
        if(srcFix){
            return imageSrc;
        }
        return SRC_PREFIX + productid + imageSrc + SRC_POSTFIX;
    }

    public void setImageSrc(String imageSrc) {
        this.imageSrc = imageSrc;
        srcFix = imageSrc.startsWith("href", 3);
        if(srcFix){
            this.imageSrc = imageSrc.replace("big", curType);
        }
    }

    public void setImageSize(String type){
        if(srcFix){
            imageSrc = imageSrc.replace(curType, type);
            curType = type;
            return;
        }
        SRC_POSTFIX = SRC_POSTFIX.replace(curType, type);
        curType = type;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public BigDecimal getUnitprice() {
        return unitprice;
    }

    public void setUnitprice(BigDecimal unitprice) {
        this.unitprice = unitprice;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCartid() {
        return cartid;
    }

    public void setCartid(int cartid) {
        this.cartid = cartid;
    }
}
